var app = angular.module('ZJPC');
app.controller('PersonListController', ['$scope','$state','$rootScope','DataService',PersonListController]);

function PersonListController ($scope,$state,$rootScope,DataService) {

	$scope.clearInput = function(e){
		$scope.search_entry = '';
	}

	$scope.searchList = []


	var carlist = []

	$scope.pageOption = {
		pageSize:10,
		itemCount:0,
		current:0
	}

	$scope.endtime = new Date().setHours(23,59,59);
	$scope.starttime = new Date().setHours(0,0,0);

	$scope.getData = function(data){
		$scope.loading = true;
		DataService.getTimePersonList($scope.starttime,$scope.endtime,$scope.pageOption.current,$scope.pageOption.pageSize,$scope.setData)

	}

	$scope.setData = function(data){
		$scope.loading = false;
		$scope.pageOption.itemCount = data.total;
		$scope.searchList  = data.data;
	}

	$scope.clickDetail = function(name,jid,li){
		$scope.$emit('detail',{type:'per-list',name:jid,li:li})
	}

	$scope.searchTrack = function(){
		$scope.loading = true;
		$scope.pageOption.current = 0;
		DataService.getTimePersonList($scope.starttime,$scope.endtime,$scope.pageOption.current,$scope.pageOption.pageSize,$scope.setData)
	}

	$scope.searchTrack();



	/*时间控件校验相关设置*/
	$scope.endDateBeforeRender = endDateBeforeRender
	$scope.endDateOnSetTime = endDateOnSetTime
	$scope.startDateBeforeRender = startDateBeforeRender
	$scope.startDateOnSetTime = startDateOnSetTime

	function startDateOnSetTime () {
	  $scope.$broadcast('start-date-changed');
	}

	function endDateOnSetTime () {
	  $scope.$broadcast('end-date-changed');
	}

	function startDateBeforeRender ($dates) {
	  if ($scope.endtime) {
	    $scope.endtime = new Date($scope.endtime).setHours(23,59,59)
	    var activeDate = moment($scope.endtime);

	    $dates.filter(function (date) {
	      return date.localDateValue() >= activeDate.valueOf()
	    }).forEach(function (date) {
	      date.selectable = false;
	    })
	  }
	}

	function endDateBeforeRender ($view, $dates) {
	  if ($scope.starttime) {
	    var activeDate = moment($scope.starttime).subtract(1, $view).add(1, 'minute');

	    $dates.filter(function (date) {
	      return date.localDateValue() <= activeDate.valueOf()
	    }).forEach(function (date) {
	      date.selectable = false;
	    })
	  }
	}

	/**/

}